home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / host contacted / jikes.lha / jikes-1.11 / src / segment.h < prev    next >
C/C++ Source or Header  |  1999-07-29  |  4KB  |  191 lines

  1. // $Id: segment.h,v 1.1 1999/07/28 23:15:48 shields Exp $
  2. //
  3. // This software is subject to the terms of the IBM Jikes Compiler
  4. // License Agreement available at the following URL:
  5. // http://www.ibm.com/research/jikes.
  6. // Copyright (C) 1996, 1999, International Business Machines Corporation
  7. // and others.  All Rights Reserved.
  8. // You must accept the terms of that agreement to use this software.
  9. //
  10. #ifndef segment_INCLUDED
  11. #define segment_INCLUDED
  12.  
  13. #include <stdio.h>
  14. #include "config.h"
  15. #include "tuple.h"
  16.  
  17. class SegmentPool;
  18.  
  19.  
  20. class PairSegment
  21. {
  22. public:
  23.  
  24.     enum
  25.     {
  26.         LIST_LIMIT = 5,
  27.         LOG_BLKSIZE = 8,
  28.         BLKSIZE = 1 << LOG_BLKSIZE,
  29.         MASK = 0xFFFFFFFF << LOG_BLKSIZE
  30.     };
  31.  
  32. private:
  33.  
  34.     class TargetValuePair
  35.     {
  36.     public:
  37.         u2 target;
  38.         u2 value;
  39.     };
  40.  
  41.     TargetValuePair list[LIST_LIMIT];
  42.     int top;
  43.     u2 *array;
  44.  
  45. public:
  46.  
  47.     PairSegment() : top(0),
  48.                     array(NULL)
  49.     {}
  50.  
  51.     ~PairSegment()
  52.     {
  53.         if (array)
  54.         {
  55.             unsigned offset = ((unsigned) list[0].target) & MASK;
  56.             delete [] (array + offset);
  57.         }
  58.     }
  59.  
  60.     u2 &Image(u2);
  61. };
  62.  
  63.  
  64. class Pair
  65. {
  66. public:
  67.  
  68.     Pair(SegmentPool &segment_pool_, int estimate = 0) : segment_pool(segment_pool_)
  69.     {
  70.         //
  71.         // DO NOT PERFORM THESE INITIALIZATION IN THE METHOD DECLARATOR !!!
  72.         // There appears to be a bug in the xlC compiler that causes base to
  73.         // not be initialized properly !!!
  74.         //
  75.         base_size = (estimate > 0 ? (estimate >> PairSegment::LOG_BLKSIZE) + 1 : 0);
  76.         base = (PairSegment **) (estimate > 0 ? memset(new PairSegment*[base_size], 0, base_size * sizeof(PairSegment *)) : NULL);
  77.     }
  78.  
  79.     ~Pair()
  80.     {
  81.         delete [] base;
  82.     }
  83.  
  84.     u2 &operator[](const u2);
  85.  
  86. private:
  87.  
  88.     SegmentPool &segment_pool;
  89.  
  90.     PairSegment **base;
  91.     int base_size;
  92. };
  93.  
  94.  
  95. class TripletSegment
  96. {
  97. public:
  98.  
  99.     enum
  100.     {
  101.         LIST_LIMIT = 5,
  102.         LOG_BLKSIZE = 8,
  103.         BLKSIZE = 1 << LOG_BLKSIZE,
  104.         MASK = 0xFFFFFFFF << LOG_BLKSIZE
  105.     };
  106.  
  107. private:
  108.  
  109.     class TargetValuePair
  110.     {
  111.     public:
  112.         u2 target;
  113.         Pair *value;
  114.     };
  115.  
  116.     SegmentPool &segment_pool;
  117.  
  118.     TargetValuePair list[LIST_LIMIT];
  119.     int top;
  120.     Pair **array;
  121.  
  122. public:
  123.  
  124.     TripletSegment(SegmentPool &segment_pool_) : segment_pool(segment_pool_),
  125.                                                  top(0),
  126.                                                  array(NULL)
  127.     {}
  128.  
  129.     ~TripletSegment()
  130.     {
  131.         if (array)
  132.         {
  133.             unsigned offset = ((unsigned) list[0].target) & MASK;
  134.             delete [] (array + offset);
  135.         }
  136.     }
  137.  
  138.     Pair &Image(u2);
  139. };
  140.  
  141.  
  142. class Triplet
  143. {
  144. public:
  145.  
  146.     Triplet(SegmentPool &segment_pool_, int estimate = 0) : segment_pool(segment_pool_)
  147.     {
  148.         //
  149.         // DO NOT PERFORM THESE INITIALIZATION IN THE METHOD DECLARATOR !!!
  150.         // There appears to be a bug in the xlC compiler that causes base to
  151.         // not be initialized properly !!!
  152.         //
  153.         base_size = (estimate > 0 ? (estimate >> TripletSegment::LOG_BLKSIZE) + 1 : 0);
  154.         base = (TripletSegment **)
  155.                (estimate > 0 ? memset(new TripletSegment*[base_size], 0, base_size * sizeof(TripletSegment *)) : NULL);
  156.     }
  157.  
  158.     ~Triplet()
  159.     {
  160.         delete [] base;
  161.     }
  162.  
  163.     u2 &Image(const u2, const u2);
  164.  
  165. private:
  166.  
  167.     SegmentPool &segment_pool;
  168.  
  169.     TripletSegment **base;
  170.     int base_size;
  171. };
  172.  
  173.  
  174. class SegmentPool
  175. {
  176.     Tuple<TripletSegment *> triplet_segment_pool;
  177.     Tuple<PairSegment *> pair_segment_pool;
  178.     Tuple<Pair *> pair_pool;
  179.  
  180. public:
  181.     SegmentPool();
  182.  
  183.     ~SegmentPool();
  184.  
  185.     Pair *AllocatePair(int estimate = 0) { return pair_pool.Next() = new Pair(*this, estimate); }
  186.     PairSegment *AllocatePairSegment() { return pair_segment_pool.Next() = new PairSegment(); }
  187.     TripletSegment *AllocateTripletSegment() { return triplet_segment_pool.Next() = new TripletSegment(*this); }
  188. };
  189.  
  190. #endif
  191.